﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text=="")
            {
                timer1.Enabled = true;
                label5.Text = "用户名不能为空";
                textBox1.Focus();
            }
            else
            {
                if (textBox1.Text.Equals("admin"))
                {
                    if (textBox2.Text.Equals("123456"))
                    {
                        MessageBox.Show("登录成功！", "登录");
                    }
                    else if (textBox2.Text == "")
                    {
                        timer1.Enabled = true;
                        label6.Text = "密码不能为空";
                        textBox2.Focus();


                    }
                    else
                    {
                        MessageBox.Show("密码错误！\n请重新输入", "登录");
                        textBox2.Text = "";
                        textBox2.Focus();
                    }
                }
                else if (textBox2.Text == "")
                {
                    timer1.Enabled = true;
                    label6.Text = "密码不能为空";
                    textBox2.Focus();
                    

                }
                else
                {
                    MessageBox.Show("用户名或密码不正确！\n请重新输入", "登录");
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox1.Focus();

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var gb = MessageBox.Show("是否退出程序！", "退出", MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
            if (gb == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            textBox1.Focus();
            
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text=="")
            {
                timer1.Enabled = true;
                label5.Text = "用户名不能为空";
                textBox1.Focus();

            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label5.Text = "";
            label6.Text = "";
        }

        private void label3_MouseEnter(object sender, EventArgs e)
        {
            label3.ForeColor = System.Drawing.Color.Red;
        }

        private void label3_MouseLeave(object sender, EventArgs e)
        {
            label3.ForeColor = System.Drawing.Color.Silver;
        }

        private void label8_MouseEnter(object sender, EventArgs e)
        {
            label8.ForeColor = System.Drawing.Color.Red;
        }

        private void label8_MouseLeave(object sender, EventArgs e)
        {
            label8.ForeColor = System.Drawing.Color.Silver;
        }

        private void label3_Click(object sender, EventArgs e)
        {
            this.Visible=false;
            Form2 form2 = new Form2();
            form2.ShowDialog();
            this.Visible = true;
        }
    }
}
